package com.silence.boot.ddd.infrastructure.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;

/**
 * @Author: silence
 */
@Configuration
public class Knife4jConfiguration {

    /**
     * 分组设置
     *
     * @return 员工组
     */
    @Bean
    public GroupedOpenApi empOpenApiGroup() {
        return GroupedOpenApi.builder()
                .group("用户管理")
                .pathsToMatch("/user/**")
                .packagesToScan("com.silence.springboot.interfaces")
                .build();
    }

    /**
     * 文档设置
     *
     * @return 文档
     */
    @Bean
    public OpenAPI docsOpenApi() {
        return new OpenAPI()
                .info(new Info()
                        .title("springboot3整合knife4j")
                        .contact(new Contact().name("silence").email("792245022@qq.com"))
                        .description("Knife4j集成springdoc-openapi示例")
                        .version("V1.0.0")
                        .termsOfService("http://doc.xiaominfo.com")
                        .license(new License().name("Apache 2.0")
                                .url("http://doc.xiaominfo.com")))
                .addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
                .components(new Components().addSecuritySchemes(HttpHeaders.AUTHORIZATION,
                        new SecurityScheme().name(HttpHeaders.AUTHORIZATION).type(SecurityScheme.Type.HTTP).scheme("bearer")))
                .externalDocs(new ExternalDocumentation()
                        .description("更多请关注官方文档")
                        .url("http://doc.xiaominfo.com"));
    }


}
